<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2023-08-25 14:31:07
 * @LastEditors: 贺楠 1071780426@qq.com
 * @LastEditTime: 2024-06-12 14:21:56
 * @FilePath: \mould\src\views\HntManage\printPage.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div>
          <!-- <el-checkbox v-model="checked" @change="see()">查看下级</el-checkbox> -->
        </div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div
        class="mechanism_nav"
        style="
          height: 100%;
          width: 100%;
          display: flex;
          justify-content: center;
          font-size: 16px;
          font-weight: 700;
        "
        v-if="isShow"
      >
        请选择项目！
      </div>
      <div class="mechanism_nav" v-else>
        <!-- 左侧 -->
        <div class="mechanism_nav_left">
          <!-- <vDatePicker
            :defaultDate="value2"
            @selectPickDate="selectTime"
            width="215px !important"
          >
          </vDatePicker> -->
           <!--
          <el-select
            style="width: 200px"
            v-model="typeText"
            placeholder="查询条件"
            @change="yj_searchForm"
          >
            <el-option
              v-for="v in stypeList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select> -->
        </div>
        <!-- 顶部按钮 -->
        <div class="print"></div>
      </div>
      <!-- 表格 -->
      <div
        class="text_table"
        v-loading="listLoading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.2)"
      >
        <iframe
          frameborder="0"
          width="100%"
          height="100%"
          :src="printLink"
        ></iframe>
        <!-- <embed :src="`${printLink}#toolbar=0`" hidden="false" type="application/pdf" height="100%" width="100%" /> -->
      </div>
    </div>
  </div>
</template>
    
<script>
// import vDatePicker from "@/components/public/v-DatePicker";
import tree from "@/components/QualityGridManage/tree"; //左侧机构树

import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
// import formJs from "./regexDetail.js"; //新增弹框配置项

import {
  getXmCompanyTreeList, //左侧机构树接口
  gethntTableNameByCompanyId,
  // getClosedLists
} from "@/api/request.js";

export default {
  name: "groupprintPage",
  data() {
    return {
      name: "groupprintPage", //按钮配置页面代号
      pickerOptions: {
        //主页面日期筛选 带快捷选项
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              // console.log(start);
              start.setTime(start.getTime());
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              // console.log(start);
              start.setTime(start.getTime() - 3600 * 1000 * 24);
              end.setTime(end.getTime() - 3600 * 1000 * 24);

              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一年",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      isShow: false,
      typeText: "按预警统计",
      // stypeList: formJs.stypeList,
      printLink: null,
      value2: "", //主页面日期筛选绑定值
      xlsxName: null,
      tableData: [], //表格列表数据列表
      tableDatas: [],
      materialData: [], //材料用量列表
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级按钮
      showName: "未选择公司",
      dialogHeight: "470px", //弹框高度
      fId: null, //点击当前列表数据fId
      checkStatus: null, //闭合状态
      // closeOperation:null, //闭合状态
      listLoading: false, //列表数据加载loading
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      // 列表给后端传参
      getList: {
        fCompanyid: "", // 施工标段id
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        beginDates: "", //上传--开始
        overDates: "", // 上传--结束
        strengthgrade: "", // 强度等级
        machineId: "", // 拌和机编号
        stationId: "", //拌合站
        keyWord: "", // 工程部位/工程名称 模糊条件
        page: 1, // 当前页码
        pageSize: 20, // 每页显示条数
        warningLevel: "", // 预警等级
        fCloseoperation: "", // 闭合状态
      },
      aaa: "按预警统计",
      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据
      // 左侧机构树
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      checkData: [], //树状图默认选中id
      userInfo: {}, //登录用户
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
        text: null,
      },
      activeNames: ["0"],
      fSourcefileList: [],
      dialogTitle: "编辑",
      tableName: null,
      companyId: null,
    };
  },
  components: {
    // vDatePicker, //时间选择器
    tree, //左侧组织机构数
    elBreadcrumb, //面包屑
  },
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));

    if (JSON.parse(sessionStorage.getItem("Quality_treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("Quality_treeCheck"));
      this.checkData = [id.fCompanyid];
      if (!this.isShow) {
        this.gethntTableNameByCompanyId(id);
      }
    } else {
      this.isShow = true;
    }
    this.getTree();
  
  },
  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        // this.yj_view = btnStr.includes("yj_view");
      } else {
        // this.yj_view = true;
      }
    },
    // 左侧树结构
    getTree() {
      this.treeText.companyId = this.userInfo.companyId;
      this.treeText.userId = this.userInfo.userId;
      getXmCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);

            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
              this.isShow = false;
              this.gethntTableNameByCompanyId(this.treeData[0].fCompanyid);
            } else if(this.treeData[0].children.length>0){
              this.treelength = true; //左侧组织机构是否显示
              this.isShow = false;
              this.gethntTableNameByCompanyId(this.treeData[0].fCompanyid);
            } else {
              this.isShow = true;
              this.treelength = true;
            }

            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("Quality_treeCheck")
              ).fShortname;
              this.getList.fCompanyid = this.checkData[0];
              this.companyId = this.checkData[0];
            } else {
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
              this.companyId = this.treeData[0].fCompanyid;
              this.checkData[0] = this.treeData[0].fCompanyid;
            }

            if (!this.isShow) {
              this.yj_searchForm(this.aaa); // 调用主页面列表接口
            }

            // 列表
          } else {
            this.$message.error(res.msg);
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },
    gethntTableNameByCompanyId(data) {
      this.companyId = data.fCompanyid;
      gethntTableNameByCompanyId({ fCompanyId: data.fCompanyid }).then(
        (res) => {
          console.log(888, res);
          if (res.errcode == "ok") {
            this.tableName = res.msg;
            this.yj_searchForm(this.aaa);
          }
        }
      );
    },
    handleNodeClick(data) {
      // console.log(data);
      if (data.fNature != "集团公司") {
        this.isShow = false;
        this.gethntTableNameByCompanyId(data);
      } else {
        this.isShow = true;
      }
      this.showName = data.fShortname; //顶部显示机构名
    
    },
    // 获取列表数据
    yj_searchForm() {

      this.listLoading = true;
      var text;
  
    text="数据报表-班组首件"

      var that = this;
      that.printLink =
        "http://xayj.limsapp.cn/qualityManagementPlatform/ureport/preview?_u=file:" +
        text +
        ".ureport.xml&fCompanyid="+
        this.companyId;

      setTimeout(() => {
        that.listLoading = false;
      }, 3000);
    },



    // 获取页面容器高度
    getHeight() {

    },

    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>
    
  <style scoped>